package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.Products_type;
import service.AdminTypeService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class AdminType {
    @Autowired
    private AdminTypeService adminTypeService;
    @RequestMapping("/addType")
    public String addType(Products_type products_type, HttpServletRequest request, Model model){
        products_type.setP_tid(Integer.valueOf(request.getParameter("p_tid")));
        products_type.setP_name(request.getParameter("p_tname"));
        int a= adminTypeService.aT(products_type);
        if (a>0){
            model.addAttribute("products_type",products_type);
            return "adminSelectAllType";
        }
        return "adminAddTypePage";
    }
    @RequestMapping("/deleteType")
    public String deleteType(Integer id,Model model){
        int a= adminTypeService.dT(id);
        if(a>0){
            model.addAttribute("msg","删除成功！");
            return "adminDeleteTypePage";
        }
        model.addAttribute("msg","删除失败！");
        return "adminDeleteTypePage";
    }
    @RequestMapping("/selectAllType")
    public String selectAllType(Model model){
        List<Products_type> list=adminTypeService.sAT();
        model.addAttribute("products_type",list);
        return "adminSelectAllType";
    }
}
